package com.branch.dellog

class AddCodeUtil {

    private static final String fileName = "Demo.java"

    static void addCode(String projectDir, DelLogExtension extension) {
        if (projectDir == null || extension == null) return
        def packageName = extension.packageName
        if (packageName == null) packageName = ""
        def packageDir = packageName.replaceAll("\\.", "/")
        LogUtil.error("packageDir:" + packageDir)
        def dir = new File(projectDir + "/" + extension.sourceDir + "/" + packageDir)
        if (!dir.exists()) dir.mkdirs()
        def cf = new File(dir, fileName)
        LogUtil.error("Demo:" + cf.toString())
        cf.createNewFile()
        cf.write("package " + packageName + ";\npublic class Demo {\npublic String test() { return \"wxl666\"; }\n}\n")
    }

}
